<template>
  <el-header :height="headerHeight + 'px'" :style="headerStyle">
      <div
        v-show="props.ifShowCollapse"
        class="collapse"
        :style="collapseStyle"
        @click="toggleCollapse"
      >
        <el-icon
          ><component :is="baseStore.isCollapse ? 'Fold' : 'Expand'"
        /></el-icon>
      </div>
      <div class="header-content">
        <slot></slot>
      </div>
  </el-header>
</template>

<script setup>
import { BaseStore } from "../stores/base_store";
// height          高度
// ifShowCollapse  判断是否展示 折叠菜单控件
// collapseStyle   icon样式
const props = defineProps({
  headerStyle: { default: {} },
  headerHeight: { default: 60 },
  ifShowCollapse: { default: true },
  collapseStyle: { default: {} },
});
// 行高=header高度 垂直居中
// 获取传递过来的CollapseStyle样式属性
const collapseStyle = {
  "line-height": props.headerHeight + "px",
  ...props.collapseStyle,
};
const headerStyle={
    display:'flex',
    ...props.headerStyle
}
// 从pinia中获取当前Collapse状态
const baseStore = BaseStore();
const emit = defineEmits();
let beforeWidth;
// 切换折叠状态
const toggleCollapse = () => {
  baseStore.toggleIsCollapse();
  if (baseStore.isCollapse) {
    beforeWidth = baseStore.asideWidth;
    baseStore.setAsideWidth(64);
  } else {
    baseStore.setAsideWidth(beforeWidth);
  }
};
</script>

<style lang="scss" scoped>
.header-content{
    flex: 1;
    flex-wrap: wrap;
    flex-shrink: 1;
}
</style>